package com.shengyijie.model.database.dataoperate;
 
 
 

import com.shengyijie.model.database.DBHandler;
import com.shengyijie.model.object.baseobject.AdvertPic;
import com.shengyijie.model.object.baseobject.User; 

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
 
public class AdvertPicDB extends DBHandler{

	public static String TABLE_ADVERT="advertpic";
	public static String COLUMN_ID="ids";
	public static String COLUMN_PIC="pic_url";
	public static String COLUMN_PRO_ID="proid";
	public static String COLUMN_NAME="name";
	public static String COLUMN_CREATE="creates";  
	public AdvertPicDB(Context ctx, String base_name, int version) {
		super(ctx, base_name, version);
	}

	public void createTable(){
		if(!isTableExits(TABLE_ADVERT)){
		   String sql = "create table "+AdvertPicDB.TABLE_ADVERT+" (ids INTEGER,name text,pic_url text,creates text,proid text);";              
           db.execSQL(sql);
		}
	}
	public void deleteTable(){
		db.execSQL("DROP TABLE IF EXISTS "+TABLE_ADVERT);
	}
	public long insertItem(int id,String name,String pic_url,String proid,String create) {
		
		ContentValues initialValues = new ContentValues();
		initialValues.put(COLUMN_ID,id); 
		initialValues.put(COLUMN_NAME,name);
		initialValues.put(COLUMN_PIC,pic_url);
		initialValues.put(COLUMN_PRO_ID,proid);
		initialValues.put(COLUMN_CREATE,create); 
		return db.insert(TABLE_ADVERT,null,initialValues);
	}
	
	public long insertItem(AdvertPic advertPic) {	 
		if(isTableExits(TABLE_ADVERT)&&advertPic!=null){ 
			return insertItem(advertPic.getId(),advertPic.getPro_name(),
					advertPic.getPic_url(),advertPic.getPro_id(),advertPic.getCreate());
		}
		    
		return -1;
	}
 

	public Cursor  fetchAllRecords(){
		if(isTableExits(TABLE_ADVERT))
		   return db.query(TABLE_ADVERT, new String[]{COLUMN_ID,COLUMN_NAME,COLUMN_PIC,COLUMN_PRO_ID,COLUMN_CREATE}, 
		            null, null, null, null, null);
		return null;
    }

	public boolean deleteAllRecords() { 
		if(isTableExits(TABLE_ADVERT))
	        return db.delete(TABLE_ADVERT, null, null) > 0;
	     return false;

	}
	 

	 
	 
	
	public SQLiteDatabase getDB(){
		return this.db;
	}
}


